import os  
import sys  
  
from string import Template  
  
def produceModel(parameters):  
    modelClass(parameters)  


def modelClass(parameters):  
    code = Template(''' 
export class ${className} {\n 
${attribute} 
${methods} 
}
''')
    name = parameters[0]    # class name  
    argv2 = parameters[1]  
    attribute = ""  
    methods = ""  
    properties = argv2.split(",")  
    for x in range(len(properties)):  
        prop = properties[x].split(":")  
        propType = prop[1]  
        propName = prop[0]  
        attribute += "    private _" + propName + ": " + propType + ";\n"
        methods += "    public set " +  propName + "(" + propName + ": " + propType + ") {\n        this._"+propName+" = " + propName + ";\n    }\n\n"  
        methods += "    public get "+ propName + "() {\n        return this._" + propName + ";\n    }\n\n"  
  
    fileStr = code.substitute(className=name, attribute=attribute, methods=methods)  
    saveFile(fileStr, name+".ts")  

def saveFile(code, path):  
    print (" " + path);  
    f = open(path,'w')  
    f.write(code)  
    f.close()  

#param1 ModelName  
#param2 Properties  
def main():  
    parameters = sys.argv[1:]  
    number = len(parameters)  
    if (number < 2):  
        print ("Error parameters")  
    else :  
        produceModel(parameters);  
  
if __name__ == "__main__":  
    main() 